﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Windows.WorkFlow.Infrastructure.EFCore.Migrations
{
    /// <inheritdoc />
    public partial class init3 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "FlowInstance",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CurrentNodeId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    CurrentNodeName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    FlowId = table.Column<long>(type: "bigint", nullable: false),
                    IsEnable = table.Column<bool>(type: "bit", nullable: false),
                    CreatedBy = table.Column<long>(type: "bigint", nullable: false),
                    CreatedByName = table.Column<string>(type: "nvarchar(50)", nullable: false),
                    CreatedOn = table.Column<DateTime>(type: "datetime", nullable: false),
                    UpdatedBy = table.Column<long>(type: "bigint", nullable: true),
                    UpdatedByName = table.Column<string>(type: "nvarchar(50)", nullable: true),
                    UpdatedOn = table.Column<DateTime>(type: "datetime", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FlowInstance", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FlowInstance_Flow_FlowId",
                        column: x => x.FlowId,
                        principalTable: "Flow",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Execution",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PId = table.Column<long>(type: "bigint", nullable: true),
                    NodeId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    NodeName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    NodeType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    StartOn = table.Column<DateTime>(type: "datetime", nullable: false),
                    EndOn = table.Column<DateTime>(type: "datetime", nullable: true),
                    FlowInstanceId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Execution", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Execution_FlowInstance_FlowInstanceId",
                        column: x => x.FlowInstanceId,
                        principalTable: "FlowInstance",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FormInstance",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Value = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
                    FlowInstanceId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FormInstance", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FormInstance_FlowInstance_FlowInstanceId",
                        column: x => x.FlowInstanceId,
                        principalTable: "FlowInstance",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Task",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    NodeId = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    NodeName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    AssigneeId = table.Column<long>(type: "bigint", nullable: false),
                    AssigneeName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    OwnerId = table.Column<long>(type: "bigint", nullable: true),
                    OwnerName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Status = table.Column<int>(type: "int", nullable: true),
                    Comment = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    StartOn = table.Column<DateTime>(type: "datetime", nullable: false),
                    EndOn = table.Column<DateTime>(type: "datetime", nullable: true),
                    ExecutionId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Task", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Task_Execution_ExecutionId",
                        column: x => x.ExecutionId,
                        principalTable: "Execution",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Identity",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MasterType = table.Column<int>(type: "int", nullable: false),
                    MasterId = table.Column<long>(type: "bigint", nullable: false),
                    TaskId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Identity", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Identity_Task_TaskId",
                        column: x => x.TaskId,
                        principalTable: "Task",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Execution_FlowInstanceId",
                table: "Execution",
                column: "FlowInstanceId");

            migrationBuilder.CreateIndex(
                name: "IX_FlowInstance_FlowId",
                table: "FlowInstance",
                column: "FlowId");

            migrationBuilder.CreateIndex(
                name: "IX_FormInstance_FlowInstanceId",
                table: "FormInstance",
                column: "FlowInstanceId");

            migrationBuilder.CreateIndex(
                name: "IX_Identity_TaskId",
                table: "Identity",
                column: "TaskId");

            migrationBuilder.CreateIndex(
                name: "IX_Task_ExecutionId",
                table: "Task",
                column: "ExecutionId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "FormInstance");

            migrationBuilder.DropTable(
                name: "Identity");

            migrationBuilder.DropTable(
                name: "Task");

            migrationBuilder.DropTable(
                name: "Execution");

            migrationBuilder.DropTable(
                name: "FlowInstance");
        }
    }
}
